﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SimpleCompiler
{
    public class StatementIf : Statement
    {
        public Statement condition = new Statement();
        public Statement trueStatement = new Statement();
        public Statement falseStatement = new Statement();

        override public Variable Execute(RuntimeVariableScope scope)
        {
            Variable v = condition.Execute(scope);
            if ((v.value as TypeBool).value)
            {
                scope.PushScope(false);
                Variable variable = trueStatement.Execute(scope);
                scope.PopScope();
                return variable;
            }
            else
            {
                scope.PushScope(false);
                Variable variable = falseStatement.Execute(scope);
                scope.PopScope();
                return variable;
            }            
        }
    }
}
